<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>

    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="new/css/global.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style lang="less" scoped>
        .home-container {
            height: 100%;
            margin: 0;
            padding: 0;
        }
        .el-header {
            background-color: #373d41;
            display: flex;
            justify-content: space-between;
            padding-left: 0;
            align-items: center;
            color: #fff;
            font-size: 20px;
        }

        .el-aside {
            background-color: #333744;
        }

        .el-main {
            background-color: #eaedf1;
        }

        .iconfont {
            margin-right: 10px;
        }

        .toggle-button {
            background-color: #4a5064;
            font-size: 10px;
            line-height: 24px;
            color: #fff;
            text-align: center;
            letter-spacing: 0.2em;
            cursor: pointer;
        }
        /* 在引入的css文件中写入这个*/
        [v-cloak]{
            display: none;
        }
    </style>
</head>
<body>
<div class="app" id="InfoManagerList" v-cloak>
    <el-container  class="home-container">
        <el-header>
            <div>
                <img src="" alt="">
                <span>I 家政后台管理</span>
            </div>
            <el-menu type="info"
                     :default-active="activeIndex2"
                     class="el-menu-demo"
                     mode="horizontal"
                     @select="handleSelect"
                     background-color="#373d41"
                     text-color="#fff"
                     active-text-color="#ffd04b">
                <el-submenu index="1">
                    <template slot="title"><i class="el-icon-s-custom"></i>我的工作台</template>
                    <el-menu-item index="2-1" @click="logout"><i class="el-icon-remove"></i>退出</el-menu-item>
                </el-submenu>
            </el-menu>
        </el-header>
        <!-- 页面主体区域 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside :width="'210px'">
                <!-- 侧边栏菜单区域 -->
                <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened
                         :collapse="isCollapse"
                         :collapse-transition="false"
                         :default-active="activePath">
                    <!-- 一级菜单 -->
                    <template  v-for="item in menuList">
                        <el-submenu v-if="item.children.length > 0" :index="item.id + ''" :key="item.id">
                            <!-- 一级菜单的模板区域 -->
                            <template slot="title">
                                <span>{{item.menuName}}</span>
                            </template>

                            <!-- 二级菜单 -->
                            <el-menu-item v-if="item.children" :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                                <template slot="title">
                                    <!-- 图标 -->
                                    <i class="el-icon-menu"></i>
                                    <!-- 文本 -->
                                    <span>{{subItem.menuName}}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                        <el-menu-item v-else  :index="item.path" :key="item.id" @click="saveNavState(item.path)">
                            <!-- 一级菜单的模板区域 -->
                            <template slot="title">
                                <span>{{item.menuName}}</span>
                            </template>
                        </el-menu-item>
                    </template>

                </el-menu>
            </el-aside>
            <!-- 右侧内容主体 -->
            <el-main>
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/AdminIndex.html' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>家政管理</el-breadcrumb-item>
                    <el-breadcrumb-item>家政列表</el-breadcrumb-item>
                </el-breadcrumb>

                <el-card>
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="标题">
                            <el-input v-model="formInline.title" placeholder="标题" clearable  @clear="clear"></el-input>
                        </el-form-item>
                        <el-form-item label="服务分类">
                            <el-select v-model="formInline.type" clearable  filterable  placeholder="服务分类">
                                <el-option
                                        v-for="item in options"
                                        :key="item.id"
                                        :label="item.name"
                                        :value="item.id" >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="用户">
                            <el-input v-model="formInline.userName" placeholder="用户" clearable  @clear="clear"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="query">查询</el-button>
                            <el-button type="primary" @click="dialogFormVisible = true">新增</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table
                            :data="tableData"
                            border
                            size="small"
                            style="width: 100%" align="center">
                        <el-table-column
                                type="index"
                                label="序号"
                                min-width="5%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="title"
                                label="服务标题"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="content"
                                label="服务描述"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="oldMoney"
                                label="原价"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="newMoney"
                                label="现价"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="typeName"
                                label="服务类型"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="userName"
                                label="服务提供者"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="heathName"
                                label="健康状态"
                                min-width="15%" align="center">
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="照片" min-width="20%" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary"  size="mini"  icon="el-icon-edit" @click="addImg(scope.row)" circle></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="操作" min-width="20%" align="center">
                            <template slot-scope="scope">
                                <el-button type="info" size="mini" icon="el-icon-delete" @click="deleteInfo(scope.row)"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="block">
                        <el-pagination
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="currentPage"
                                :page-sizes="[5, 10, 20, 50]"
                                :page-size="10"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="total">
                        </el-pagination>
                    </div>
                </el-card>
            </el-main>
        </el-container>
    </el-container>
    <el-dialog title="服务页面" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="家政名称" :label-width="formLabelWidth" >
                <el-input v-model="form.title" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="家政分类" :label-width="formLabelWidth">
                <el-select v-model="form.type" clearable  filterable  placeholder="家政分类">
                    <el-option
                            v-for="item in options"
                            :key="item.name"
                            :label="item.name"
                            :value="item.id" >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工作描述:" :label-width="formLabelWidth">
                <el-select v-model="form.heathType" placeholder="请选择">
                    <el-option id="1" label="健康" value="1"></el-option>
                    <el-option id="2" label="良好" value="2"></el-option>
                    <el-option id="3" label="一般" value="3"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工作描述" :label-width="formLabelWidth">
                <el-input type="textarea" v-model="form.content"></el-input>
            </el-form-item>
            <el-form-item label="联系人名称" :label-width="formLabelWidth">
                <el-input v-model="form.userName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="原价" :label-width="formLabelWidth">
                <el-input v-model="form.oldMoney">
                    <template slot="append">元</template>
                </el-input>
            </el-form-item>
            <el-form-item label="现价" :label-width="formLabelWidth" >
                <el-input v-model="form.newMoney">
                    <template slot="append">元</template>
                </el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveInfo">确 定</el-button>
        </div>
    </el-dialog>

    <el-dialog title="图片页面" :visible.sync="dialogImgVisible">
        <el-upload
                class="upload-demo"
                action="/file/upload"
                accept="image/*"
                :data="fileData"
                :limit="imgLimit"
                :multiple="isMultiple"
                :on-preview="handlePreview"
                :before-remove="handleRemove"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
                :on-exceed="handleExceed"
                :on-error="imgUploadError"
                :file-list="fileList"
                list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
    </el-dialog>
</div>

<script src="js/vue.js"></script>
<!-- Jquery Js -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/2.3/layer.js"></script>
<script src="js/common.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script>
    var vm = new Vue({
        el : "#InfoManagerList",
        data : {
            formInline:{
                title:'',
                type : '',
                userName : '',
                page : 1,
                size : 10
            },
            fileList:[],
            fileData:{
                id : '',
                user:'li'
            },
            isMultiple: true,
            imgLimit: 6,
            form: {
                title: '',
                type: '',
                heathType: '',
                content : '',
                userName : '',
                oldMoney : '',
                newMoney : ''
            },
            addInfoId: '',
            formLabelWidth: '120px',
            dialogFormVisible : false,
            dialogImgVisible: false,
            options:[],
            currentPage : 1,
            total : 0,
            tableData: [],

            activeIndex2: '1',
            // 左侧菜单数据
            menuList: [],

            // 是否折叠
            isCollapse: false,
            // 被激活的链接地址
            activePath: ''
        },

        created() {
            this.getInfoList()
            this.getTypes()
            this.getMenuList()
            this.activePath = window.localStorage.getItem('activePath')
        },
        methods: {
            addImg(info){
                const that = this;
                that.fileList = [];
                this.fileData.id = info.id;
                HttpGet("/file/info/"+info.id,null,function (res) {
                    if (res.result == true){
                        that.fileList = res.data;
                    }
                })
                this.dialogImgVisible = true;
            },
            beforeAvatarUpload(file) {//文件上传之前调用做一些拦截限制
                console.log(file);
                const isJPG = true;
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isLt2M) {
                    layer.msg("上传图片大小不能超过 2MB!",{icon:2,time:1500});
                }
                return isJPG && isLt2M;
            },
            handleAvatarSuccess(res, file) {//图片上传成功
                console.log(res);
                console.log(file);
                this.imageUrl = URL.createObjectURL(file.raw);
            },
            handleExceed(files, fileList) {//图片上传超过数量限制
                layer.msg("上传图片不能超过6张!",{icon:2,time:1500});
            },
            imgUploadError(err, file, fileList){//图片上传失败调用
                console.log(err)
                layer.msg("上传图片失败!",{icon:2,time:1500});
            },

            getInfoList(){
                const that = this;
                const queryParam = {
                    "title": that.formInline.title,
                    "type": that.formInline.type,
                    "userName":that.formInline.userName,
                    "page": that.formInline.page,
                    "size":that.formInline.size
                };
                HttpGet("/info/getList",queryParam,function (result) {
                    if(result.result == true){
                        that.tableData = result.data.data;
                        that.total = result.data.total;
                    }else{
                        layer.msg("查询失败，请稍后重试......",{icon:2,time:1500});
                    }
                })
            },
            saveInfo(){
                const that = this;
                HttpPost("/info/saveInfo",that.form,function (res) {
                    if (res.result == true){
                        layer.msg("新增成功",{icon:1,time:1500,},function () {
                            that.getInfoList();
                            that.getTypes();
                            that.dialogFormVisible = false;
                            that.form = {}
                        });
                    }else{
                        layer.msg("查询失败，请稍后重试......",{icon:2,time:1500});
                    }
                })
            },
            getTypes(){
                var that = this;
                HttpGet("/type/getChildren",null,function (res) {
                    if (res.result == true){
                        that.options = res.data;
                    }
                })
            },
            getMenuList(){
                const that = this;
                HttpGet("/menu/getList",null,function(result){
                    if (result.result == true){
                        that.menuList = result.data;
                    }
                })
            },
            deleteInfo(info){
                const that = this;
                HttpGet("/info/delete/"+info.id,null,function (res) {
                    if(res.result == true){
                        layer.msg("删除成功",{icon:1,time:1500});
                        that.query();
                    }else{
                        layer.msg("删除失败，请稍后重试......",{icon:2,time:1500});
                    }

                })
            },
            query(){
                this.formInline.page = 1;
                this.formInline.page = 10;
                this.getInfoList();
            },

            handleRemove(file, fileList) {
                console.log("asdf");
                console.log(file.name);
                HttpGet("/file/delete/"+file.name,null,null);
            },
            handlePreview(file) {
                console.log("asdf")
                console.log(file);
            },
            clear (){
                this.getInfoList();
            },

            handleSizeChange(val) {
                const size = this.formInline.size;
                if (val === size){
                    return;
                }
                this.formInline.size = val;
                this.getInfoList();
            },
            handleCurrentChange(val) {
                const page = this.formInline.page;
                if (val === page){
                    return;
                }
                this.formInline.page = val;
                this.getInfoList();
            },
            query (){
                this.formInline.page = 1;
                this.formInline.size = 10;
                this.getInfoList();
            },

            handleSelect(){

            },
            logout() {
                layer.msg("用户退出成功",{icon:1,time:1500},function () {
                    window.localStorage.clear()
                    window.location.href="AdminLogin.html";
                });
            },
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            // 保存链接的激活状态
            saveNavState(activePath) {
                window.localStorage.setItem('activePath', activePath)
                this.activePath = activePath
                window.location.href = activePath;
            }
        }
    });

</script>

</body>
</html>
